package com.kaifamiao.month04.day05;

import java.util.Arrays;

public class Queue {

    Object[] elements = new String[10];
    int count = 0;

    public boolean offer(Object str) {
        grow();
        elements[count++] = str;
        return true;
    }

    private void grow() {
        if (count == elements.length) {
            elements = Arrays.copyOf(elements,count << 1);
        }
    }

    public Object peek() {
        if (count == 0) {
            return null;
        }
        return elements[0];
    }

    public Object poll() {
        Object str = elements[0];
        Object[] newStr = new Object[elements.length - 1];
        System.arraycopy(elements, 1, newStr, 0, elements.length - 1);
        elements = newStr;
        return str;
    }
}
